
    <main class="lyear-layout-content">

        <div class="container-fluid p-t-15">

            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-toolbar d-flex flex-column flex-md-row">
                            <form class="search-bar" method="get" action="{:url('admin/order/orderlist')}" role="form">
                                <input type="hidden" name="search_field" id="search-field" value="code" />
                                <div class="input-group ml-md-auto">
                                    <div class="input-group-prepend">
                                        <button class="btn btn-default dropdown-toggle" type="button"
                                            data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
                                            id="search-btn">商品单号</button>
                                        <div class="dropdown-menu">
                                            <a class="dropdown-item" data-field="code">商品单号</a>
                                            <a class="dropdown-item" data-field="expcode">配送单号</a>
                                        </div>
                                    </div>
                                    <input type="text" class="form-control" name="keyword" placeholder="请输入相应搜索订单号">
                                </div>
                            </form>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th>商品订单号</th>
                                            <th>购买用户</th>
                                            <th>配送单号</th>
                                            <th>下单时间</th>
                                            <th>订单状态</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {foreach $orderList as $item}
                                        <tr>
                                            <td>{$item['code']}</td>
                                            <td>{$item['user']['nickname']}</td>
                                            <td>{$item['expcode'] ? $item['expcode']: '暂无配送单号'}</td>
                                            <td>{$item['createtime']}</td>
                                            {if condition="$item['status']==1"}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-success">已支付</span>
                                            </td>
                                            {elseif condition="$item['status']==2"}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-info">已发货</span>
                                            </td>
                                            {elseif condition="$item['status']==3"}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-cyan">已收货</span>
                                            </td>
                                            {elseif condition="$item['status']==4"}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-primary">已评价</span>
                                            </td>
                                            {elseif condition="$item['status']==-1"}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-secondary">退货</span>
                                            </td>
                                            {elseif condition="$item['status']==-2"}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-danger">申请退货</span>
                                            </td>
                                            {else /}
                                            <td style="vertical-align: middle;"><span
                                                    class="badge btn-sm btn-warning">退货被拒</span>
                                            </td>
                                            {/if}
                                            <td>
                                                <div class="btn-group">
                                                    {if condition="$item['status']==1"}
                                                    <a type="button" class="btn btn-info btn-sm btn-default " title=""
                                                        id="ajax-Ship" data-id="{$item.id}"
                                                        data-target="#ShipModalChange" data-toggle="modal"
                                                        data-original-title="发货">发货</a>
                                                    {/if}
                                                    <a class="btn btn-warning btn-sm btn-default ajax-Details" title=""
                                                        data-id="{$item.id}" data-target="#DetailsModalCenter"
                                                        data-toggle="modal" data-original-title="查看详情">查看详情</a>
                                                </div>
                                            </td>
                                        </tr>
                                        {/foreach}
                                    </tbody>
                                </table>
                            </div>
                            {$orderList->render()}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <!-- 发货模态框 -->
    <div class="modal fade" id="ShipModalChange" tabindex="-1" role="dialog" aria-labelledby="exampleModalChangeLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h6 class="modal-title" id="exampleModalChangeTitle">选择物流发货</h6>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="input-group mb-3">
                            <div class="input-group-prepend">
                                <label class="input-group-text" for="expid">选择物流公司</label>
                            </div>
                            <select class="custom-select" id="expid" name="expid">
                                {foreach $expressList as $item}
                                <option value="{$item.id}">{$item['name']}</option>
                                {/foreach}
                            </select>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary ajax-Ship-Save" data-dismiss="modal">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 查看详情模态框 -->
    <div class="modal fade" id="DetailsModalCenter" tabindex="-1" role="dialog"
        aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h6 class="modal-title" id="exampleModalCenterTitle">订单详情</h6>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="container">
                        <div class="row">
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">收货人：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-nickname" readonly>
                                </div>
                            </div>
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">订单状态：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-order-status" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">收获详细地址：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-address" readonly>
                                </div>
                            </div>
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">订单总价：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-total" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">手机号码：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-tel" readonly>
                                </div>
                            </div>
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">商品单价：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-price" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">订单号：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-code" readonly>
                                </div>
                            </div>
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">下单数量：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-nums" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">配送单号：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-expcode" readonly>
                                </div>
                            </div>
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">配送公司：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-expname" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">订单描述：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-order-content" readonly>
                                </div>
                            </div>
                            <div class="col">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon3">下单时间：</span>
                                    </div>
                                    <input type="text" class="form-control" id="basic-createtime" readonly>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        // 传送对象数据
        // $('#ShipModalChange').modal(options)
        // $('#DetailsModalCenter').modal(options)
// 传送发送人数据
//  $('#exampleModalChange').on('show.bs.modal', function (event) {
//     var button = $(event.relatedTarget);
//     var recipient = button.data('whatever');
//     var modal = $(this);
//     modal.find('.modal-title').text('New message to ' + recipient);
//     modal.find('.modal-body input').val(recipient);
// })
    layui.use(['layer'], function () {
        let $ = layui.jquery,
            layer = layui.layer
            
        //搜索框的点击
        $('.search-bar .dropdown-menu a').click(function () {
            var field = $(this).data('field') || '';
            $('#search-field').val(field);
            $('#search-btn').html($(this).text());
        });

        $('.ajax-Ship-Save').click(function () {
        let id = $('#ajax-Ship').data('id')
        let expid = Number($('#expid').val());
        // console.log(userid,id);
        // return false;
            //发起请求
            $.ajax({
                type: 'post',
                url: `{:url('admin/order/orderlist')}`,
                data: {
                    id,
                    expid,
                    action: 'OrderShip'
                },
                dataType: 'json',
                success: function (res) {
                    if (res.code === 1) {
                        layer.msg('发货成功', { icon: 1 }, function (index) {
                            location.href = res.url
                        })
                    } else {
                        layer.msg(res.msg, { icon: 5 })
                    }
                }
            })
        })

        $('.ajax-Details').click(function () {
        let id = $(this).data('id')
        // console.log(id);
        // return false;
            //发起请求
            $.ajax({
                type: 'post',
                url: `{:url('admin/order/orderlist')}`,
                data: {
                    id,
                    action: 'OrderDetails'
                },
                dataType: 'json',
                success: function (res) {
                    if (res.code === 1) {
                        // console.log(res.data);
                        $('#basic-nickname').val(res.data.user.nickname)
                        $('#basic-order-status').val(res.data.status_text)
                        $('#basic-address').val(res.data.address.address_text)
                        $('#basic-total').val(res.data.total+"元")
                        $('#basic-tel').val(res.data.address.mobile)
                        $('#basic-price').val(res.data.OrderProValue.priceValue)
                        $('#basic-code').val(res.data.code)
                        $('#basic-nums').val(res.data.OrderProValue.nums)
                        if(res.data.expcode){
                            $('#basic-expcode').val(res.data.expcode)
                        } else {
                            $('#basic-expcode').val('该无配送单号')
                        }
                        $('#basic-expname').val(res.data.express.name)
                        if(res.data.content){
                            $('#basic-order-content').val(res.data.content)
                        } else {
                            $('#basic-order-content').val('该订单暂无什么内容')
                        }
                        $('#basic-createtime').val(res.data.createtime)
                        // layer.msg('查询成功', { icon: 1 })
                    } else {
                        layer.msg(res.msg, { icon: 5 })
                    }
                }
            })
        })
    })
    </script>
